import { ConfigProvider, Form } from 'antd'
import zhCN from 'antd/es/locale/zh_CN'
import type { CSSProperties } from 'react'
import { useEffect } from 'react'
import Layout from './layout'
import { dependencyConfigState } from './store'
import 'uno.css'
import type { ModuleProps } from './store/Schema'

export interface DependencyItem {
  libraryName?: string // 显示的模块名称
  libraryGlobalImport?: string // 模块引入名
  libraryUrl?: string // 模块 url
  libraryVersion?: string // 模块 版本
  linkUrl?: string[] // 样式文件
  moduleConfig?: ModuleConfig[]
}

export interface ModuleConfig {
  // 组件类别
  moduleName: string
  hasSlot?: boolean
  isNative?: boolean
  formPropsConfig?: ModuleProps
  defaultProps?: Record<string, any>
  destructuring?: boolean
  exportName?: string
  subName?: string
}

export type DependencyConfig = DependencyItem[]

function OneCodes(props: {
  dependencyConfig: DependencyConfig
  style?: CSSProperties
}) {
  const { dependencyConfig = [], style } = props

  useEffect(() => {
    dependencyConfigState.dependencyConfigState = dependencyConfig
  }, [])

  return (
    <ConfigProvider
      locale={zhCN}
      theme={{
        token: {
          colorPrimary: '#2558fb',
        },
      }}
    >
      <Layout style={style} />
    </ConfigProvider>
  )
}

OneCodes.Form = Form

// OneCodes.Slot = function (props: { children: JSX.Element }) {
//   return <>{props.children}</>;
// };

export { antd5 } from './presets/antd5'
export { antd5ProComponents } from './presets/antd5-pro-components'
export { reactPreset } from './presets/reactPreset'
export default OneCodes
